package server;

import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

import persistent.MigratorServer;
import persistent.Persistent;

import frame.Frame;

public class Starter {
	
	public static final int MAX_FRAMES_AUX_QUEUES = 1000;
	
	private BlockingQueue<Frame> persistentQueue;
	
	public Starter(){
		
		persistentQueue = new ArrayBlockingQueue<Frame>(MAX_FRAMES_AUX_QUEUES);
	}
	
	public void start() throws IOException{
		
		System.out.println("Servidor principal iniciado...");
		
		FramesServer frames = new FramesServer();
		frames.setPersistentQueue(persistentQueue);
		frames.start();
		
		AlertsServer alerts = new AlertsServer();
		alerts.setPersistentQueue(persistentQueue);
		alerts.start();
		
		Persistent persistent = new Persistent(persistentQueue);
		//persistent.start();
		
		InstructionsListener instructor = new InstructionsListener(frames, alerts);
		instructor.start();
		
		MigratorServer migrator = new MigratorServer();
		migrator.start();
	}
	
	public static void main(String[] args) {
		
		try{
			Starter s = new Starter();
			s.start();
		}
		catch(IOException e){
			e.printStackTrace();
		}
		
	}

}
